package java02;

import java.util.Arrays;

public class ShellSort {
	public static void main(String[] args) {
		int[] a={5,3,7,2,9,8,1,4};
		shellSort(a,a.length);
	}
	private static void shellSort(int[] arr, int n)
	{
		int gap = n;
		while(gap>1)
		{
			gap = gap / 2;
			for(int i = 0; i < n - gap; ++i)
			{
				int end = i;
				int tem = arr[end + gap];
				while (end >= 0)
				{
					if (tem < arr[end])
					{
						arr[end + gap] = arr[end];
						end = end - gap;
					}
					else
					{
						break;
					}
				}
				arr[end + gap] = tem;
				System.out.println(Arrays.toString(arr));
			}
		}
	}
}
